package com.yanqu.road.server.cmd.passRoad;

import com.yanqu.road.entity.config.passroad.PassRoadInfo;
import com.yanqu.road.entity.config.passroad.PassRoadPointInfo;
import com.yanqu.road.entity.player.UserPassRoad;
import com.yanqu.road.logic.pb.PassRoadPb;
import com.yanqu.road.pb.pass.RoadProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.passRoad.PassRoadModule;
import com.yanqu.road.server.manger.config.PassRoadMgr;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.Protocol;

import java.util.List;


@Cmd(code = Protocol.S_PASS_ROAD_GET_CONFIG, desc = "新关卡配置请求")
public class GetPassRoadConfigCmd extends AbstractCommand {


	@Override
	public boolean parseData(YanQuMessage packet) throws Exception {
		return true;
	}

	@Override
	public void execute(GamePlayer player, YanQuMessage packet) throws Exception {

	}

	@Override
	public void sendData(GamePlayer player) {
		RoadProto.RoadConfigMsg.Builder configMsg = RoadProto.RoadConfigMsg.newBuilder();
		UserPassRoad userPassRoad = player.getModule(PassRoadModule.class).getUserPassRoad();
		if(userPassRoad.getPassId() <= PassRoadMgr.getLastPassRoadInfo().getId()){
			List<PassRoadPointInfo> pointList = PassRoadMgr.getPassRoadPointList(userPassRoad.getPassId());
			PassRoadInfo passRoadInfo = PassRoadMgr.getPassRoadInfo(userPassRoad.getPassId());
			List<Integer> sliverCostParamList = PassRoadMgr.getCostMinMaxParam(passRoadInfo.getId());
			configMsg = PassRoadPb.parsePassRoadConfigMsg(pointList,passRoadInfo,sliverCostParamList);
		}
		player.sendPacket(Protocol.U_PASS_ROAD_GET_CONFIG, configMsg);
	}
}
